$(document).ready(function(){
	//tin
	$('.wd-datepicker').datepicker({
        inline: true,
        showOtherMonths: true,
        dayNamesMin: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
        dateFormat: 'dd-mm-yy',
        yearRange: '-100y:c+nn',
        showOn: 'both',
        buttonImageOnly: true,
        buttonImage: "/theme/Technology/img/front/date-picker.png",
        changeMonth: true,
        changeYear: true
    });
	//----------------
	$("#submit-view-day").click(function(){
		from=$("#from-day").val();
		to=$("#to-day").val();
		if(from && to){
			document.location.href='/admin/node/node/order_index/'+from+'/'+to+'.html';
		}
	});
	$('.check_paid').click(function(){
		console.log(this.id);
		id=this.id;
		paid=$("#check-paid-"+id+"-1:checked").length;
		received=$("#check-paid-"+id+"-2:checked").length;
		// console.log($("#check-paid-"+id+"-2"));
		// console.log(received);
		loading='<div class="wd-loading"><span id="wd-loading"></span></div>';
		if(received==1){
			$(loading).appendTo($("body"));
			console.log('received');
			$.ajax({
				url:'/vie/admin/node/node/orderUpdate/1/'+id+'.html',
				success: function(data){
					document.location.href='/admin/node/node/order_index';
				}
			});
		}else if (paid==1) {
			console.log('paid');
			$(loading).appendTo($("body"));
			$.ajax({
				url:'/vie/admin/node/node/orderUpdate/2/'+id+'.html',
				success: function(data){
					document.location.href='/admin/node/node/order_index';
				}
			});
		};
	});

	$('.edit-item').click(function(){
		id=this.id.substring(2);
		// console.log(id);
		value=$("#item-value-"+id).val();
		value=value.replace(',','.');
		// console.log(value);
		if (id) {
			$.ajax({
				type:"POST",
				url:'/vie/admin/node/node/edit_item/'+id+'.html',
				data:{ value:value},
				success: function(data){
					 document.location.reload();
				}
			});

		};
	});
	$('.delete-item').click(function(){
		id=this.id.substring(2);
		console.log(id);
		// value=$("#item-value-"+id).val();
		// value=value.replace(',','.');
		// console.log(value);
		if (id) {
			$.ajax({
				type:"POST",
				url:'/vie/admin/node/node/delete_item/'+id+'.html',
				// data:{ value:value},
				success: function(data){
					 document.location.reload();
				}
			});

		};
	});

});